﻿using System;
using Repository;
using System.Collections.Generic;
using Models;
using ViewModels;
using AutoMapper;

namespace Service
{
    public class BusinessEntityService
    {
        private IBusinessEntity _iBusuinessEntity;


        public BusinessEntityService(IBusinessEntity iBusinessEntity)
        {
            _iBusuinessEntity = iBusinessEntity;
            Mapper.Initialize(cf =>
            {
                cf.CreateMap<BusinessEntity, VbusinessEntity>();
                cf.CreateMap<VbusinessEntity, BusinessEntity>();
            });//创建到vo的映射
           
        }

        public VbusinessEntity FindByid(int id)
        {
            BusinessEntity businessEntity = _iBusuinessEntity.FindById(id);
            return Mapper.Map<VbusinessEntity>(businessEntity);
        }

        public dynamic Add(VbusinessEntity vBusinessEntity)
        {
            BusinessEntity businessEntity = Mapper.Map<BusinessEntity>(vBusinessEntity);
            dynamic id = _iBusuinessEntity.Add(businessEntity);
            return id;
        }
    }
}
